import {ref} from 'vue';
import {Props} from '@/components/typing'

export  function getPaginationConfig(){
    let flowPagination = ref<any>({
        current:1,
        pageSize:10,
        total: 25,
        pageSizeOptions:['10', '15', '20', '25','30','50','100'],
        showSizeChanger: true,
        change: function(page:any, pageSize:any){
          flowPagination.current = page
          flowPagination.pageSize = pageSize
        }
      })
    return flowPagination;
}

export  function formatFilter(filters: any){
    let filter:Props = {};
    if (filters && Object.keys(filters).length > 0){
        for (let key in filters){
          if (filters[key] && filters[key].length > 0){
            let val = filters[key][0];
            filter[key] = val;
          }
        }
      }
    return filter;
}

export  function formatFilterLike(filters: any){
    let filter:Props = {};
    if (filters && Object.keys(filters).length > 0){
        for (let key in filters){
          if (filters[key] && filters[key].length > 0){
            let val = filters[key][0];
            filter[key + 'Like'] = val;
          }
        }
      }
    return filter;
}

export function formatSortParam(sorter: any){
    let sort = '';
    if (sorter && Object.keys(sorter).length > 0 && sorter.order){
        sort = sorter.field;//排序按钮状态
        if (sorter.order === 'ascend'){
          sort += ' asc'//升序
        }else{
          sort += ' desc'//降序
        }
    }
    return sort;
}